using System;
using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	[AddComponentMenu("MaterialUI/Shadow Anim", 100)]
	[RequireComponent(typeof(CanvasGroup))]
	[RequireComponent(typeof(Image))]
	public class AnimatedShadow : MonoBehaviour
	{
		[HideInInspector]
		[SerializeField]
		private bool m_IsVisible;

		private CanvasGroup m_CanvasGroup;

		private int m_Tweener;

		public bool isVisible
		{
			get
			{
				return m_IsVisible;
			}
			set
			{
				m_IsVisible = value;
			}
		}

		public CanvasGroup canvasGroup
		{
			get
			{
				if (m_CanvasGroup == null)
				{
					m_CanvasGroup = GetComponent<CanvasGroup>();
				}
				return m_CanvasGroup;
			}
		}

		public void SetShadow(bool set, bool instant = false)
		{
			SetShadow(set, Tween.TweenType.EaseOutQuint, instant);
		}

		public void SetShadow(bool set, Tween.TweenType tweenType, bool instant = false)
		{
			isVisible = set;
			if (set)
			{
				base.gameObject.SetActive(value: true);
			}
			if (Application.isPlaying && !instant)
			{
				TweenManager.EndTween(m_Tweener);
				Action<float> updateValue = delegate(float f)
				{
					canvasGroup.alpha = f;
				};
				Func<float> startValue = () => canvasGroup.alpha;
				float targetValue = (!set) ? 0f : 1f;
				float duration = 0.5f;
				float delay = 0f;
				Action callback = delegate
				{
					base.gameObject.SetActive(set);
				};
				m_Tweener = TweenManager.TweenFloat(updateValue, startValue, targetValue, duration, delay, callback, scaledTime: false, tweenType);
			}
			else
			{
				canvasGroup.alpha = ((!set) ? 0f : 1f);
				base.gameObject.SetActive(set);
			}
		}
	}
}
